/* eslint-disable @typescript-eslint/naming-convention */
/**
 * @Date 2021-07-22 16:42:13
 * @Remark
 */

// lib
// config
// script & methods & public
// http
import { open, bag, isOkRes } from "@/public/http/api";
// state
// service
import { simpleObjectService } from "@/public/service/simple.service";
// api
import { API_CODE, API_LOGIN, DataLogin, ReqCode, ReqLogin, ResCode, ResLogin } from "./api";
// interface && type && class
// 其它

// 登录
export async function loginService(params: ReqLogin) {
  // 打开接口
  const result = await simpleObjectService<ReqLogin, ResLogin, DataLogin>(API_LOGIN, params);
  if (result.payload) {
    // userState.setToken(result.payload.token);
  }
  return result;
}

// 发送手机验证码
export async function getCodeService(params: string) {
  // 打开接口
  const a1 = await open<ReqCode, ResCode>(API_CODE, {
    mobile: params.trim(),
  });
  // 创建返回数据
  const data = bag<string>(a1);
  // 成功后处理
  if (isOkRes(a1)) {
    data.payload = a1.data.code || "";
  }
  return data;
}
